package com.tanhua.sso.controller;

//import com.tanhua.sso.service.UserService;
//import com.tanhua.sso.vo.ErrorResult;
//import com.tanhua.sso.vo.LoginResult;

import com.tanhua.sso.service.UserInfoService;
import com.tanhua.sso.service.UserService;
import com.tanhua.sso.vo.ErrorResult;
import com.tanhua.sso.vo.LoginResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/*
 * 处理手机号登陆的接口
 * */
@RestController
@RequestMapping("user")
@Slf4j
public class UserInfoController {


    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("loginReginfo")
    public ResponseEntity<Object> loginReginfo(@RequestHeader("Authorization") String token, @RequestBody Map<String, String> param) {

        boolean flag = userInfoService.loginReginfo(token, param);
        if (flag){
            return ResponseEntity.ok(null);
        }
        return ResponseEntity.status(500).body(ErrorResult.builder().errCode("00001").errMessage("保存失败").build());
    }


    @PostMapping("loginReginfo/head")
    public ResponseEntity<Object> saveUserLogo(@RequestParam("headPhoto") MultipartFile file,
                                               @RequestHeader("Authorization") String token) {
        try {
            Boolean bool = this.userInfoService.saveUserLogo(file, token);
            if (bool) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("保存用户logo失败！").build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }
}
